package com.yaxin.gallery;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class GuidePagerAdapter extends PagerAdapter
{
    private ArrayList<Fragment> listFragments;

    private List<Integer> list;
    private Context context;

    public GuidePagerAdapter(Context context, List<Integer> list)
    {
        this.context = context;
        this.list = list;
    }

    //    public GuidePagerAdapter(Context context,ArrayList<Fragment> listFragments) {
//        this.context = context;
//        this.listFragments = listFragments;
//    }
    @Override
    public int getCount()
    {
//		return null == listFragments ? 0 : listFragments.size();
        return list == null ? 0 : list.size() <= 1 ? list.size() : Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object)
    {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        View view = LayoutInflater.from(context).inflate(R.layout.item_gallery, null);
        ImageView iv = (ImageView) view.findViewById(R.id.iv);
        TextView tv = (TextView) view.findViewById(R.id.tv);
        iv.setImageResource(list.get(position % list.size()));
        tv.setText("我的" + position % list.size());
        container.addView(view);
        return view;
//        ImageView ivEEE = new ImageView(context);
//        ivEEE.setImageResource(list.get(position % list.size()));
//        container.addView(ivEEE);
//        return ivEEE;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        container.removeView((View) object);
    }
}
